package September10.CompanyTest;

import java.util.ArrayList;
import java.util.List;

class Employee {
    private String name;
    private int age;
    private String gender;
    private String position;
    private double salary;
    private String id; // 工号

    public Employee(String name, int age, String gender, String position, double salary, String id) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.position = position;
        this.salary = salary;
        this.id = id;
    }

    // Getters and Setters
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getGender() {
        return gender;
    }

    public String getPosition() {
        return position;
    }

    public double getSalary() {
        return salary;
    }

    public String getId() {
        return id;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", position='" + position + '\'' +
                ", salary=" + salary +
                ", id='" + id + '\'' +
                '}';
    }
}

class Company {
    private String companyName;
    private String registeredAddress;
    private String phone;
    private String businessScope;
    private List<Employee> employees;

    public Company(String companyName, String registeredAddress, String phone, String businessScope) {
        this.companyName = companyName;
        this.registeredAddress = registeredAddress;
        this.phone = phone;
        this.businessScope = businessScope;
        this.employees = new ArrayList<>();
    }

    public void hireEmployee(Employee employee) {
        if (!hasEmployeeWithId(employee.getId())) {
            employees.add(employee);
            System.out.println("Employee " + employee.getName() + " has been hired.");
        } else {
            System.out.println("Cannot hire employee with duplicate ID.");
        }
    }

    public void fireEmployee(String id) {
        employees.removeIf(employee -> employee.getId().equals(id));
        System.out.println("Employee with ID " + id + " has been fired.");
    }

    public void printEmployeeInfo() {
        for (Employee employee : employees) {
            System.out.println(employee);
        }
    }

    public void countEmployees() {
        System.out.println("Total number of employees: " + employees.size());
    }

    public Employee getHighestPaidEmployee() {
        return employees.stream()
                .max((e1, e2) -> Double.compare(e1.getSalary(), e2.getSalary()))
                .orElse(null);
    }

    private boolean hasEmployeeWithId(String id) {
        return employees.stream().anyMatch(employee -> employee.getId().equals(id));
    }
}
